{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "import keras\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from keras.models import Sequential, Model\n",
    "from keras.layers import Input, Dense, Dropout, BatchNormalization\n",
    "from keras.layers.advanced_activations import LeakyReLU\n",
    "from keras.optimizers import Adam\n",
    "from sklearn.preprocessing import LabelEncoder\n",
    "from sklearn.utils import shuffle\n",
    "from mysql import SQLConnector"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def build_discriminator(layer1, layer2, layer3, alpha):\n",
    "    model = Sequential()\n",
    "    model.add(Dense(layer1, input_dim=41)) #discriminator takes 41 values from our dataset\n",
    "    model.add(LeakyReLU(alpha=alpha))\n",
    "    model.add(Dropout(0.3))\n",
    "    model.add(Dense(layer2))\n",
    "    model.add(LeakyReLU(alpha=alpha))\n",
    "    model.add(Dropout(0.3))\n",
    "    model.add(Dense(layer3))\n",
    "    model.add(LeakyReLU(alpha=alpha))\n",
    "    model.add(Dropout(0.3))\n",
    "    model.add(Dense(1, activation='sigmoid')) #outputs 0 to 1, 1 being real and 0 being fake\n",
    "\n",
    "    attack = Input(shape=(41,))\n",
    "    validity = model(attack)\n",
    "\n",
    "    return Model(attack, validity)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def build_generator(layer1, layer2, layer3, alpha):\n",
    "    model = Sequential()\n",
    "    model.add(Dense(layer1, input_dim=41))\n",
    "    model.add(BatchNormalization())\n",
    "    model.add(LeakyReLU(alpha=alpha))\n",
    "    model.add(Dense(layer2))\n",
    "    model.add(BatchNormalization())\n",
    "    model.add(LeakyReLU(alpha=alpha))\n",
    "    model.add(Dense(layer3))\n",
    "    model.add(BatchNormalization())\n",
    "    model.add(LeakyReLU(alpha=alpha))\n",
    "    model.add(Dense(41, activation='relu'))\n",
    "\n",
    "    noise = Input(shape=(41,))\n",
    "    attack = model(noise)\n",
    "    return Model(noise, attack)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def GAN_model(layer1, layer2, layer3, alpha):\n",
    "    optimizer = Adam(0.001)\n",
    "    \n",
    "    #build generator and discriminator (mirrored)\n",
    "    generator = build_generator(layer1, layer2, layer3, alpha)\n",
    "    \n",
    "    discriminator = build_discriminator(layer3, layer2, layer1, alpha)\n",
    "    discriminator.compile(loss='binary_crossentropy', optimizer=optimizer, metrics=['accuracy'])\n",
    "    \n",
    "    #input and output of our combined model\n",
    "    z = Input(shape=(41,))\n",
    "    attack = generator(z)\n",
    "    validity = discriminator(attack)\n",
    "    \n",
    "    #build combined model from generator and discriminator\n",
    "    combined = Model(z, validity)\n",
    "    combined.compile(loss='binary_crossentropy', optimizer=optimizer)\n",
    "    return combined, discriminator, generator"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "ll = [\"duration\", \"protocol_type\", \"service\", \"flag\", \"src_bytes\", \"dst_bytes\", \"land\", \"wrong_fragment\", \"urgent\", \n",
    "            \"hot\", \"num_failed_logins\", \"logged_in\", \"num_compromised\", \"root_shell\", \"su_attempted\", \"num_root\", \"num_file_creations\", \n",
    "            \"num_shells\", \"num_access_files\", \"num_outbound_cmds\", \"is_host_login\", \"is_guest_login\", \"count\", \"srv_count\", \"serror_rate\", \n",
    "            \"srv_serror_rate\", \"rerror_rate\", \"srv_rerror_rate\", \"same_srv_rate\", \"diff_srv_rate\", \"srv_diff_host_rate\", \"dst_host_count\", \n",
    "            \"dst_host_srv_count\", \"dst_host_same_srv_rate\", \"dst_host_diff_srv_rate\", \"dst_host_same_src_port_rate\", \n",
    "            \"dst_host_srv_diff_host_rate\", \"dst_host_serror_rate\", \"dst_host_srv_serror_rate\", \"dst_host_rerror_rate\", \n",
    "            \"dst_host_srv_rerror_rate\", \"attack_type\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "def train_loop(combined, discriminator, generator, estimator, epochs):\n",
    "    epochs = epochs+1\n",
    "    batch_size = 30\n",
    "    conn = SQLConnector()\n",
    "    data = conn.pull_kdd99(attack='nmap', num=1554)\n",
    "    dataframe = pd.DataFrame.from_records(data=data,\n",
    "                columns=conn.pull_kdd99_columns(allQ=True))\n",
    "    \n",
    "    #apply \"le.fit_transform\" to every column (usually only works on 1 column)\n",
    "    le = LabelEncoder()\n",
    "    dataframe_encoded = dataframe.apply(le.fit_transform)\n",
    "    dataset = dataframe_encoded.values\n",
    "    \n",
    "    f = open(\"NmapReal.txt\", \"a\")\n",
    "    np.savetxt(\"NmapReal.txt\", dataset, fmt=\"%d\")\n",
    "    f.close()\n",
    "    \n",
    "    #labels for data. 1 for valid attacks, 0 for fake (generated) attacks\n",
    "    valid = np.ones((batch_size, 1))\n",
    "    fake = np.zeros((batch_size, 1))\n",
    "    \n",
    "    #Set X as our input data and Y as our label\n",
    "    X_train = dataset[:, 0:41].astype(int)\n",
    "    Y_train = dataset[:, 41]\n",
    "    \n",
    "    #break condition for training (when diverging)\n",
    "    loss_increase_count = 0\n",
    "    prev_g_loss = 0\n",
    "    \n",
    "    #generating a np array of numbers 0..batch_size-1\n",
    "    idx = np.arange(batch_size)\n",
    "    \n",
    "    for epoch in range(epochs):\n",
    "        #selecting batch_size random attacks from our training data\n",
    "        #idx = np.random.randint(0, X_train.shape[0], batch_size)\n",
    "        attacks = X_train[idx-1]\n",
    "        \n",
    "        #generate a matrix of noise vectors\n",
    "        noise = np.random.normal(0, 1, (batch_size, 41))\n",
    "        \n",
    "        #create an array of generated attacks\n",
    "        gen_attacks = generator.predict(noise)\n",
    "        \n",
    "        #loss functions, based on what metrics we specify at model compile time\n",
    "        d_loss_real = discriminator.train_on_batch(attacks, valid)\n",
    "        d_loss_fake = discriminator.train_on_batch(gen_attacks, fake)\n",
    "        d_loss = 0.5 * np.add(d_loss_real, d_loss_fake)\n",
    "        \n",
    "        #generator loss function\n",
    "        g_loss = combined.train_on_batch(noise, valid)\n",
    "        \n",
    "        if epoch % 50 == 0:\n",
    "            print(\"%d [D loss: %f, acc.: %.2f%%] [G loss: %f] [Loss change: %.3f, Loss increases: %.0f]\" % \n",
    "                  (epoch, d_loss[0], 100 * d_loss[1], g_loss, g_loss - prev_g_loss, loss_increase_count))\n",
    "        \n",
    "            #saving results to txt to track them as the gan is training\n",
    "            f = open(\"Nmap.txt\", \"a\")\n",
    "            np.savetxt(\"Nmap.txt\", gen_attacks, fmt=\"%d\")\n",
    "            f.close()\n",
    "            \n",
    "            y_pred = estimator.predict(gen_attacks)\n",
    "        \n",
    "            right = (y_pred > 0.98).sum()\n",
    "            wrong = len(y_pred)-(y_pred > 0.98).sum()\n",
    "            accuracy = (right/float(right+wrong))\n",
    "            print(\"Number of right predictions: %d\" % right)\n",
    "            print(\"Number of wrong predictions: %d\" % wrong)\n",
    "            print(\"Accuracy: %.4f \" % accuracy)      "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 0 0 ... 1 1 1]\n"
     ]
    }
   ],
   "source": [
    "conn = SQLConnector()\n",
    "data = conn.pull_kdd99(attack='nmap', num=1554)\n",
    "data += conn.pull_kdd99(attack='normal', num=1554)\n",
    "dataframe = pd.DataFrame.from_records(data=data,\n",
    "            columns=conn.pull_kdd99_columns(allQ=True))\n",
    "\n",
    "#LabelEncoder, turns all our categorical data into integers\n",
    "le = LabelEncoder()\n",
    "\n",
    "dataframe_encoded = dataframe.apply(le.fit_transform)\n",
    "dataset = dataframe_encoded.values\n",
    "\n",
    "#Set X as our input data and Y as our label\n",
    "X = dataset[:,0:41].astype(int)\n",
    "Y = dataset[:,41]\n",
    "print(Y)\n",
    "X, Y = shuffle(X, Y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Get validation data\n",
    "validationToTrainRatio = 0.10\n",
    "validationSize = int(validationToTrainRatio * len(X))\n",
    "validationData = X[:validationSize]\n",
    "validationLabels = Y[:validationSize]\n",
    "X = X[validationSize:]\n",
    "Y = Y[validationSize:]\n",
    "\n",
    "#Get test data\n",
    "testToTrainRatio = 0.10\n",
    "testSize = int(testToTrainRatio * len(X))\n",
    "testData = X[:testSize]\n",
    "testLabels = Y[:testSize]\n",
    "X = X[testSize:]\n",
    "Y = Y[testSize:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "def baseline_model(layers, units, dropout_rate, input_shape, num_classes):\n",
    "    model = Sequential()\n",
    "    model.add(Dropout(rate=dropout_rate, input_shape=input_shape))\n",
    "    for _ in range(layers-1):\n",
    "        model.add(Dense(units=units, activation='relu'))\n",
    "        model.add(Dropout(rate=dropout_rate))\n",
    "\n",
    "    model.add(Dense(units=num_classes, activation='sigmoid'))\n",
    "    model.compile(optimizer=Adam(0.001),\n",
    "              loss='binary_crossentropy',\n",
    "              metrics=['accuracy'])\n",
    "    return model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From /home/ldeng/anaconda3/envs/ml/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py:423: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Colocations handled automatically by placer.\n",
      "WARNING:tensorflow:From /home/ldeng/anaconda3/envs/ml/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:3445: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use `rate` instead of `keep_prob`. Rate should be set to `rate = 1 - keep_prob`.\n",
      "WARNING:tensorflow:From /home/ldeng/anaconda3/envs/ml/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Use tf.cast instead.\n",
      "Train on 2519 samples, validate on 310 samples\n",
      "Epoch 1/200\n",
      " - 1s - loss: 6.6433 - acc: 0.5042 - val_loss: 7.1385 - val_acc: 0.5290\n",
      "Epoch 2/200\n",
      " - 0s - loss: 6.0969 - acc: 0.5280 - val_loss: 5.8557 - val_acc: 0.5903\n",
      "Epoch 3/200\n",
      " - 0s - loss: 5.7502 - acc: 0.5534 - val_loss: 5.0466 - val_acc: 0.6452\n",
      "Epoch 4/200\n",
      " - 0s - loss: 5.2581 - acc: 0.5879 - val_loss: 4.2942 - val_acc: 0.6935\n",
      "Epoch 5/200\n",
      " - 0s - loss: 5.0003 - acc: 0.5955 - val_loss: 3.4859 - val_acc: 0.7452\n",
      "Epoch 6/200\n",
      " - 0s - loss: 4.6453 - acc: 0.6252 - val_loss: 3.2013 - val_acc: 0.7677\n",
      "Epoch 7/200\n",
      " - 0s - loss: 4.1059 - acc: 0.6610 - val_loss: 1.9920 - val_acc: 0.7903\n",
      "Epoch 8/200\n",
      " - 0s - loss: 3.6945 - acc: 0.6765 - val_loss: 1.0234 - val_acc: 0.9000\n",
      "Epoch 9/200\n",
      " - 0s - loss: 3.4357 - acc: 0.6900 - val_loss: 0.7561 - val_acc: 0.9226\n",
      "Epoch 10/200\n",
      " - 0s - loss: 3.3929 - acc: 0.6963 - val_loss: 0.6761 - val_acc: 0.9323\n",
      "Epoch 11/200\n",
      " - 0s - loss: 3.2439 - acc: 0.7102 - val_loss: 0.6133 - val_acc: 0.9452\n",
      "Epoch 12/200\n",
      " - 0s - loss: 2.9936 - acc: 0.7312 - val_loss: 0.6055 - val_acc: 0.9484\n",
      "Epoch 13/200\n",
      " - 0s - loss: 2.7765 - acc: 0.7451 - val_loss: 0.6215 - val_acc: 0.9452\n",
      "Epoch 14/200\n",
      " - 0s - loss: 2.6154 - acc: 0.7539 - val_loss: 0.6100 - val_acc: 0.9516\n"
     ]
    }
   ],
   "source": [
    "estimator = baseline_model(layers=2, units=32, dropout_rate=0.5, input_shape=X.shape[1:], num_classes=1)\n",
    "\n",
    "callbacks = [keras.callbacks.EarlyStopping(\n",
    "        monitor='val_loss', patience=2)]\n",
    "\n",
    "history = estimator.fit(X,\n",
    "                    Y,\n",
    "                    epochs=200,\n",
    "                    batch_size=256,\n",
    "                    callbacks=callbacks,\n",
    "                    validation_data=(validationData, validationLabels),\n",
    "                    verbose=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "279/279 [==============================] - 0s 16us/step\n",
      "[0.6490930596142874, 0.9354838718222888]\n"
     ]
    }
   ],
   "source": [
    "#Evalueating model on the testset\n",
    "#[loss, accuracy]\n",
    "print(estimator.evaluate(testData, testLabels))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "#creating GAN model\n",
    "combined, discriminator, generator = GAN_model(8, 16, 32, 0.2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 [D loss: 0.977581, acc.: 55.00%] [G loss: 0.331942] [Loss change: 0.332, Loss increases: 0]\n",
      "Number of right predictions: 0\n",
      "Number of wrong predictions: 30\n",
      "Accuracy: 0.0000 \n",
      "50 [D loss: 1.051328, acc.: 53.33%] [G loss: 0.298288] [Loss change: 0.298, Loss increases: 0]\n",
      "Number of right predictions: 0\n",
      "Number of wrong predictions: 30\n",
      "Accuracy: 0.0000 \n",
      "100 [D loss: 1.030586, acc.: 51.67%] [G loss: 0.211810] [Loss change: 0.212, Loss increases: 0]\n",
      "Number of right predictions: 0\n",
      "Number of wrong predictions: 30\n",
      "Accuracy: 0.0000 \n",
      "150 [D loss: 1.056385, acc.: 50.00%] [G loss: 0.262110] [Loss change: 0.262, Loss increases: 0]\n",
      "Number of right predictions: 0\n",
      "Number of wrong predictions: 30\n",
      "Accuracy: 0.0000 \n",
      "200 [D loss: 0.987014, acc.: 53.33%] [G loss: 0.340660] [Loss change: 0.341, Loss increases: 0]\n",
      "Number of right predictions: 0\n",
      "Number of wrong predictions: 30\n",
      "Accuracy: 0.0000 \n",
      "250 [D loss: 1.050032, acc.: 51.67%] [G loss: 0.316486] [Loss change: 0.316, Loss increases: 0]\n",
      "Number of right predictions: 0\n",
      "Number of wrong predictions: 30\n",
      "Accuracy: 0.0000 \n",
      "300 [D loss: 1.030098, acc.: 55.00%] [G loss: 0.413799] [Loss change: 0.414, Loss increases: 0]\n",
      "Number of right predictions: 0\n",
      "Number of wrong predictions: 30\n",
      "Accuracy: 0.0000 \n"
     ]
    }
   ],
   "source": [
    "#training GAN model\n",
    "train_loop(combined, discriminator, generator, estimator, 300)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2.9802322e-07]\n",
      "[1.2814999e-06]\n",
      "[0.00041047]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.0002225]\n",
      "[2.1010637e-05]\n",
      "[3.5762787e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00026593]\n",
      "[1.013279e-06]\n",
      "[1.7881393e-07]\n",
      "[8.940697e-08]\n",
      "[3.5762787e-07]\n",
      "[5.9604645e-08]\n",
      "[0.00415692]\n",
      "[0.]\n",
      "[2.1457672e-06]\n",
      "[2.8729439e-05]\n",
      "[0.00021309]\n",
      "[0.00302839]\n",
      "[1.7464161e-05]\n",
      "[0.00017974]\n",
      "[0.]\n",
      "[5.1259995e-06]\n",
      "[3.5762787e-07]\n",
      "[2.3841858e-07]\n",
      "[0.]\n",
      "[0.01252121]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[2.3841858e-07]\n",
      "[0.]\n",
      "[8.940697e-08]\n",
      "[1.4007092e-06]\n",
      "[1.79708e-05]\n",
      "[0.00021601]\n",
      "[2.9802322e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[5.9604645e-08]\n",
      "[0.]\n",
      "[0.]\n",
      "[5.9604645e-08]\n",
      "[2.9802322e-08]\n",
      "[3.695488e-06]\n",
      "[0.]\n",
      "[8.34465e-07]\n",
      "[0.00023457]\n",
      "[3.2782555e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00083429]\n",
      "[0.]\n",
      "[0.00017855]\n",
      "[0.]\n",
      "[3.2782555e-07]\n",
      "[0.74377215]\n",
      "[0.]\n",
      "[0.]\n",
      "[4.5865774e-05]\n",
      "[8.34465e-07]\n",
      "[8.136034e-06]\n",
      "[0.8179622]\n",
      "[0.]\n",
      "[0.]\n",
      "[1.4901161e-06]\n",
      "[0.]\n",
      "[9.641051e-05]\n",
      "[2.7030706e-05]\n",
      "[0.00012609]\n",
      "[0.]\n",
      "[0.]\n",
      "[1.7285347e-06]\n",
      "[7.209182e-05]\n",
      "[0.]\n",
      "[3.5583973e-05]\n",
      "[0.2788751]\n",
      "[1.5079975e-05]\n",
      "[0.]\n",
      "[1.4305115e-06]\n",
      "[0.]\n",
      "[1.3113022e-06]\n",
      "[8.940697e-08]\n",
      "[6.2584877e-07]\n",
      "[0.00032851]\n",
      "[0.]\n",
      "[2.682209e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[2.0861626e-07]\n",
      "[0.]\n",
      "[0.86714256]\n",
      "[0.9964808]\n",
      "[1.4901161e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[1.2814999e-06]\n",
      "[0.]\n",
      "[0.9990485]\n",
      "[0.]\n",
      "[2.0861626e-07]\n",
      "[0.]\n",
      "[0.3579356]\n",
      "[0.00093904]\n",
      "[2.9802322e-07]\n",
      "[0.00031903]\n",
      "[1.1920929e-06]\n",
      "[0.00071561]\n",
      "[5.9604645e-08]\n",
      "[1.7881393e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[6.854534e-07]\n",
      "[0.]\n",
      "[2.0861626e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[9.268522e-06]\n",
      "[0.00030237]\n",
      "[1.2487173e-05]\n",
      "[9.834766e-07]\n",
      "[0.01669899]\n",
      "[0.]\n",
      "[0.00796583]\n",
      "[0.9238374]\n",
      "[6.836653e-05]\n",
      "[5.632639e-06]\n",
      "[0.00046068]\n",
      "[0.]\n",
      "[0.00027871]\n",
      "[2.9802322e-08]\n",
      "[0.00105649]\n",
      "[0.00021797]\n",
      "[0.]\n",
      "[0.]\n",
      "[4.7683716e-07]\n",
      "[0.]\n",
      "[0.6254608]\n",
      "[3.1292439e-06]\n",
      "[0.00029439]\n",
      "[1.1771917e-05]\n",
      "[0.0003655]\n",
      "[0.86618334]\n",
      "[0.]\n",
      "[0.]\n",
      "[1.4305115e-06]\n",
      "[5.751848e-06]\n",
      "[0.]\n",
      "[2.9802322e-07]\n",
      "[0.00022075]\n",
      "[5.9604645e-08]\n",
      "[0.]\n",
      "[1.1622906e-06]\n",
      "[0.]\n",
      "[1.4513731e-05]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00179482]\n",
      "[0.00031444]\n",
      "[0.]\n",
      "[1.3113022e-06]\n",
      "[0.]\n",
      "[0.04381865]\n",
      "[0.]\n",
      "[0.]\n",
      "[5.9604645e-07]\n",
      "[5.3346157e-06]\n",
      "[3.874302e-07]\n",
      "[0.]\n",
      "[0.03542805]\n",
      "[8.940697e-08]\n",
      "[0.4932861]\n",
      "[3.5762787e-07]\n",
      "[0.]\n",
      "[3.5762787e-07]\n",
      "[5.570054e-05]\n",
      "[1.2218952e-05]\n",
      "[0.]\n",
      "[1.5795231e-06]\n",
      "[8.940697e-08]\n",
      "[2.95043e-06]\n",
      "[0.00195813]\n",
      "[7.5906515e-05]\n",
      "[0.9429741]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[3.5762787e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00018376]\n",
      "[2.682209e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[2.6255846e-05]\n",
      "[0.]\n",
      "[0.08972088]\n",
      "[0.00019437]\n",
      "[4.172325e-07]\n",
      "[0.]\n",
      "[4.887581e-06]\n",
      "[0.]\n",
      "[0.00017878]\n",
      "[0.]\n",
      "[1.0788441e-05]\n",
      "[0.]\n",
      "[1.7285347e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[1.7881393e-07]\n",
      "[7.95424e-05]\n",
      "[0.]\n",
      "[0.0002954]\n",
      "[0.29968986]\n",
      "[1.1920929e-06]\n",
      "[3.2782555e-07]\n",
      "[2.3245811e-05]\n",
      "[2.3186207e-05]\n",
      "[4.7683716e-07]\n",
      "[0.00018209]\n",
      "[1.1920929e-06]\n",
      "[4.4703484e-07]\n",
      "[0.0002574]\n",
      "[0.]\n",
      "[0.]\n",
      "[5.492568e-05]\n",
      "[0.]\n",
      "[2.9802322e-07]\n",
      "[0.]\n",
      "[1.66893e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[7.4505806e-07]\n",
      "[7.301569e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[2.2649765e-06]\n",
      "[2.3841858e-07]\n",
      "[0.10521644]\n",
      "[0.0001702]\n",
      "[5.9604645e-08]\n",
      "[0.00049648]\n",
      "[9.834766e-06]\n",
      "[1.1622906e-06]\n",
      "[8.3595514e-05]\n",
      "[6.854534e-07]\n",
      "[9.9629164e-05]\n",
      "[0.00217044]\n",
      "[1.630187e-05]\n",
      "[9.7215176e-05]\n",
      "[0.]\n",
      "[1.1920929e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00027806]\n",
      "[5.1885843e-05]\n",
      "[1.3113022e-06]\n",
      "[0.]\n",
      "[1.4901161e-07]\n",
      "[0.]\n",
      "[0.33495688]\n",
      "[2.9802322e-07]\n",
      "[0.]\n",
      "[2.9802322e-08]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00059578]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.01653579]\n",
      "[2.2649765e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[1.1920929e-07]\n",
      "[8.314848e-06]\n",
      "[0.]\n",
      "[0.01202601]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.01881143]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[6.854534e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[2.4437904e-06]\n",
      "[4.9471855e-06]\n",
      "[0.00558695]\n",
      "[0.]\n",
      "[0.0001483]\n",
      "[0.00031096]\n",
      "[0.]\n",
      "[0.]\n",
      "[2.9414892e-05]\n",
      "[0.99810517]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[4.3213367e-05]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00878677]\n",
      "[0.]\n",
      "[2.682209e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[5.0246716e-05]\n",
      "[1.4603138e-06]\n",
      "[0.]\n",
      "[2.6881695e-05]\n",
      "[0.0003292]\n",
      "[0.00027323]\n",
      "[3.5762787e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[5.364418e-07]\n",
      "[5.978346e-05]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[4.4703484e-07]\n",
      "[0.]\n",
      "[0.00018936]\n",
      "[3.874302e-07]\n",
      "[0.]\n",
      "[8.7320805e-06]\n",
      "[2.861023e-05]\n",
      "[2.9802322e-08]\n",
      "[2.682209e-07]\n",
      "[3.5762787e-07]\n",
      "[7.1525574e-07]\n",
      "[0.8526397]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00024676]\n",
      "[1.7285347e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.01470351]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[1.2427568e-05]\n",
      "[0.]\n",
      "[0.]\n",
      "[1.7881393e-07]\n",
      "[5.9604645e-08]\n",
      "[1.3709068e-06]\n",
      "[0.99654645]\n",
      "[1.3113022e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00018722]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.04178533]\n",
      "[0.]\n",
      "[0.]\n",
      "[1.7881393e-07]\n",
      "[5.543232e-06]\n",
      "[9.23872e-07]\n",
      "[7.0035458e-06]\n",
      "[0.00030786]\n",
      "[4.7683716e-07]\n",
      "[0.]\n",
      "[2.115965e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[1.7881393e-07]\n",
      "[0.00043133]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00120351]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00018123]\n",
      "[0.00019002]\n",
      "[1.3113022e-06]\n",
      "[0.00026628]\n",
      "[0.8544418]\n",
      "[0.00081697]\n",
      "[1.4901161e-07]\n",
      "[0.]\n",
      "[0.9149915]\n",
      "[0.00398761]\n",
      "[0.00316581]\n",
      "[0.00017235]\n",
      "[5.6892633e-05]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.0001893]\n",
      "[0.]\n",
      "[1.7881393e-07]\n",
      "[0.]\n",
      "[0.00027958]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[5.5611134e-05]\n",
      "[1.4901161e-07]\n",
      "[0.]\n",
      "[0.00013378]\n",
      "[4.133582e-05]\n",
      "[9.23872e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00017095]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00011134]\n",
      "[0.00029457]\n",
      "[0.]\n",
      "[3.1590462e-06]\n",
      "[0.00100231]\n",
      "[9.23872e-07]\n",
      "[0.]\n",
      "[5.64456e-05]\n",
      "[0.]\n",
      "[0.00034702]\n",
      "[1.0728836e-06]\n",
      "[0.]\n",
      "[0.00038159]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.8115337]\n",
      "[3.5136938e-05]\n",
      "[1.1622906e-06]\n",
      "[0.]\n",
      "[0.00023085]\n",
      "[0.]\n",
      "[3.874302e-07]\n",
      "[0.]\n",
      "[5.066395e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.2644323]\n",
      "[0.]\n",
      "[0.]\n",
      "[4.2021275e-06]\n",
      "[0.]\n",
      "[0.16204438]\n",
      "[0.]\n",
      "[0.00728977]\n",
      "[0.0004496]\n",
      "[0.02131432]\n",
      "[0.00210628]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.04802582]\n",
      "[0.]\n",
      "[0.]\n",
      "[1.2040138e-05]\n",
      "[0.]\n",
      "[1.4901161e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[4.8726797e-05]\n",
      "[0.]\n",
      "[0.00021982]\n",
      "[1.3113022e-06]\n",
      "[0.]\n",
      "[3.5762787e-07]\n",
      "[4.172325e-07]\n",
      "[1.7881393e-07]\n",
      "[0.]\n",
      "[0.01580712]\n",
      "[0.]\n",
      "[3.8444996e-06]\n",
      "[4.3570995e-05]\n",
      "[5.6505203e-05]\n",
      "[0.98091376]\n",
      "[8.055568e-05]\n",
      "[1.7881393e-07]\n",
      "[1.4603138e-06]\n",
      "[2.9802322e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00022247]\n",
      "[1.1056662e-05]\n",
      "[0.]\n",
      "[2.9802322e-08]\n",
      "[5.5134296e-06]\n",
      "[2.0861626e-07]\n",
      "[4.172325e-07]\n",
      "[1.7374754e-05]\n",
      "[4.4703484e-07]\n",
      "[1.0877848e-05]\n",
      "[0.]\n",
      "[0.00083598]\n",
      "[0.]\n",
      "[5.9604645e-08]\n",
      "[0.]\n",
      "[0.00016955]\n",
      "[0.]\n",
      "[5.64754e-05]\n",
      "[0.]\n",
      "[0.02898327]\n",
      "[0.00021443]\n",
      "[0.]\n",
      "[2.682209e-06]\n",
      "[0.00010681]\n",
      "[1.4901161e-07]\n",
      "[0.]\n",
      "[1.7285347e-06]\n",
      "[2.413988e-06]\n",
      "[8.940697e-08]\n",
      "[0.00221312]\n",
      "[0.]\n",
      "[1.5199184e-06]\n",
      "[0.]\n",
      "[2.9802322e-07]\n",
      "[0.0001443]\n",
      "[4.0352345e-05]\n",
      "[2.3841858e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[5.9604645e-08]\n",
      "[4.172325e-07]\n",
      "[1.4841557e-05]\n",
      "[0.00032866]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.02717]\n",
      "[5.364418e-07]\n",
      "[0.]\n",
      "[2.0802021e-05]\n",
      "[0.]\n",
      "[5.9604645e-08]\n",
      "[0.]\n",
      "[0.01373738]\n",
      "[0.00017741]\n",
      "[0.00018007]\n",
      "[0.9792017]\n",
      "[0.]\n",
      "[0.4712245]\n",
      "[5.453825e-06]\n",
      "[0.]\n",
      "[1.7285347e-06]\n",
      "[1.2099743e-05]\n",
      "[4.3988228e-05]\n",
      "[1.0758638e-05]\n",
      "[5.841255e-06]\n",
      "[0.0001837]\n",
      "[0.]\n",
      "[2.2649765e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[1.6093254e-05]\n",
      "[8.6426735e-07]\n",
      "[0.]\n",
      "[3.5762787e-07]\n",
      "[0.]\n",
      "[0.0465993]\n",
      "[0.]\n",
      "[1.4901161e-07]\n",
      "[0.]\n",
      "[0.05278313]\n",
      "[1.0073185e-05]\n",
      "[0.00018093]\n",
      "[0.00016853]\n",
      "[0.00026053]\n",
      "[0.]\n",
      "[0.99538714]\n",
      "[5.453825e-06]\n",
      "[1.1920929e-06]\n",
      "[0.97555685]\n",
      "[4.172325e-07]\n",
      "[1.4603138e-06]\n",
      "[5.9604645e-08]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00018641]\n",
      "[0.]\n",
      "[0.]\n",
      "[1.3411045e-06]\n",
      "[0.]\n",
      "[0.00010395]\n",
      "[4.172325e-07]\n",
      "[0.00030532]\n",
      "[1.3411045e-06]\n",
      "[0.00020176]\n",
      "[0.]\n",
      "[0.]\n",
      "[7.4505806e-07]\n",
      "[0.]\n",
      "[8.34465e-07]\n",
      "[5.662441e-07]\n",
      "[0.]\n",
      "[0.00013375]\n",
      "[0.]\n",
      "[0.00019342]\n",
      "[0.]\n",
      "[0.]\n",
      "[1.5795231e-06]\n",
      "[3.0845404e-05]\n",
      "[0.]\n",
      "[0.00015947]\n",
      "[0.]\n",
      "[0.]\n",
      "[1.4901161e-07]\n",
      "[0.]\n",
      "[0.00014856]\n",
      "[0.00022382]\n",
      "[0.00039518]\n",
      "[1.3411045e-06]\n",
      "[8.314848e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[5.364418e-07]\n",
      "[2.9802322e-08]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[4.172325e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.91603166]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[3.9339066e-06]\n",
      "[2.1457672e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00011128]\n",
      "[2.3841858e-07]\n",
      "[2.682209e-07]\n",
      "[0.]\n",
      "[5.1617622e-05]\n",
      "[0.]\n",
      "[1.1920929e-07]\n",
      "[2.3841858e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[1.013279e-06]\n",
      "[6.854534e-07]\n",
      "[0.]\n",
      "[0.02419642]\n",
      "[0.]\n",
      "[1.1920929e-07]\n",
      "[2.3841858e-07]\n",
      "[1.3709068e-06]\n",
      "[3.5762787e-07]\n",
      "[8.6426735e-07]\n",
      "[0.]\n",
      "[0.0004921]\n",
      "[0.]\n",
      "[2.7239323e-05]\n",
      "[0.]\n",
      "[0.00034812]\n",
      "[2.9802322e-08]\n",
      "[0.9812638]\n",
      "[0.00046712]\n",
      "[0.]\n",
      "[3.6358833e-06]\n",
      "[1.013279e-06]\n",
      "[0.10064089]\n",
      "[1.7285347e-06]\n",
      "[0.00900874]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00013402]\n",
      "[0.]\n",
      "[0.00019914]\n",
      "[1.9669533e-06]\n",
      "[0.]\n",
      "[7.531047e-05]\n",
      "[8.940697e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00016087]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.52312386]\n",
      "[0.00014248]\n",
      "[0.]\n",
      "[9.23872e-07]\n",
      "[2.9802322e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.9214306]\n",
      "[0.]\n",
      "[0.9717214]\n",
      "[6.5863132e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[9.864569e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[7.748604e-07]\n",
      "[7.688999e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[8.940697e-08]\n",
      "[0.]\n",
      "[1.874566e-05]\n",
      "[0.]\n",
      "[0.]\n",
      "[5.9604645e-08]\n",
      "[9.819865e-05]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00013897]\n",
      "[0.00029889]\n",
      "[0.03232348]\n",
      "[4.172325e-07]\n",
      "[1.2040138e-05]\n",
      "[2.7537346e-05]\n",
      "[2.092123e-05]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.03830788]\n",
      "[1.2814999e-06]\n",
      "[3.579259e-05]\n",
      "[2.3841858e-07]\n",
      "[4.4703484e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[2.9802322e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[6.2584877e-07]\n",
      "[0.00033391]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00044882]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00024331]\n",
      "[6.2286854e-06]\n",
      "[0.00017342]\n",
      "[0.]\n",
      "[9.262562e-05]\n",
      "[0.00031331]\n",
      "[6.455183e-05]\n",
      "[0.00035319]\n",
      "[0.]\n",
      "[0.]\n",
      "[6.2286854e-06]\n",
      "[2.8908253e-06]\n",
      "[0.9063314]\n",
      "[9.834766e-07]\n",
      "[0.]\n",
      "[2.7120113e-05]\n",
      "[4.4703484e-07]\n",
      "[5.9604645e-05]\n",
      "[0.]\n",
      "[0.8465611]\n",
      "[0.00018385]\n",
      "[4.4703484e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00025904]\n",
      "[0.]\n",
      "[0.00027135]\n",
      "[0.00015712]\n",
      "[1.5795231e-06]\n",
      "[8.34465e-07]\n",
      "[0.62766534]\n",
      "[0.00017753]\n",
      "[1.4901161e-07]\n",
      "[2.7120113e-06]\n",
      "[0.]\n",
      "[1.7881393e-06]\n",
      "[0.00020096]\n",
      "[3.5762787e-07]\n",
      "[2.0861626e-07]\n",
      "[5.298853e-05]\n",
      "[0.00038445]\n",
      "[0.00479031]\n",
      "[8.940697e-08]\n",
      "[0.]\n",
      "[1.6391277e-06]\n",
      "[1.6987324e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[2.9802322e-07]\n",
      "[0.00091738]\n",
      "[2.1457672e-06]\n",
      "[2.3752451e-05]\n",
      "[1.7881393e-07]\n",
      "[1.1622906e-06]\n",
      "[2.682209e-07]\n",
      "[0.00156486]\n",
      "[0.]\n",
      "[0.9751029]\n",
      "[0.]\n",
      "[4.7683716e-07]\n",
      "[9.247661e-05]\n",
      "[1.2516975e-06]\n",
      "[1.1920929e-06]\n",
      "[3.2484531e-06]\n",
      "[0.]\n",
      "[6.556511e-06]\n",
      "[4.5210123e-05]\n",
      "[0.00018793]\n",
      "[0.]\n",
      "[0.00018495]\n",
      "[1.6391277e-06]\n",
      "[1.9699335e-05]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[2.9802322e-07]\n",
      "[0.00033092]\n",
      "[0.05420101]\n",
      "[0.99547297]\n",
      "[0.]\n",
      "[1.4007092e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00021112]\n",
      "[0.]\n",
      "[2.4735928e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00024772]\n",
      "[1.7881393e-07]\n",
      "[0.00047573]\n",
      "[0.]\n",
      "[0.02784359]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[1.7881393e-06]\n",
      "[2.9802322e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[3.2782555e-07]\n",
      "[0.]\n",
      "[2.95043e-06]\n",
      "[3.132224e-05]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[5.662441e-07]\n",
      "[0.00076136]\n",
      "[0.]\n",
      "[0.00209662]\n",
      "[0.]\n",
      "[0.]\n",
      "[2.682209e-07]\n",
      "[7.483363e-05]\n",
      "[0.]\n",
      "[0.01642585]\n",
      "[1.2218952e-05]\n",
      "[4.568696e-05]\n",
      "[0.]\n",
      "[0.]\n",
      "[2.9802322e-08]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[1.1265278e-05]\n",
      "[0.03708836]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00133023]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00021741]\n",
      "[0.]\n",
      "[8.34465e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[9.575486e-05]\n",
      "[0.]\n",
      "[0.]\n",
      "[2.041459e-05]\n",
      "[2.9802322e-08]\n",
      "[5.364418e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[1.5377998e-05]\n",
      "[0.]\n",
      "[5.0097704e-05]\n",
      "[1.2814999e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.05633858]\n",
      "[1.758337e-06]\n",
      "[0.77065337]\n",
      "[2.682209e-07]\n",
      "[1.4513731e-05]\n",
      "[4.7683716e-07]\n",
      "[0.]\n",
      "[2.0503998e-05]\n",
      "[2.2351742e-06]\n",
      "[0.]\n",
      "[4.798174e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[8.657575e-05]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.9586401]\n",
      "[0.00016332]\n",
      "[0.00023103]\n",
      "[0.00015846]\n",
      "[1.1920929e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[5.3346157e-06]\n",
      "[0.]\n",
      "[5.9604645e-08]\n",
      "[3.5762787e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[3.3676624e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00037849]\n",
      "[6.854534e-07]\n",
      "[2.9802322e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00017637]\n",
      "[0.]\n",
      "[0.]\n",
      "[2.6524067e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[8.85129e-05]\n",
      "[0.00022101]\n",
      "[0.00017521]\n",
      "[0.01042563]\n",
      "[0.]\n",
      "[5.066395e-07]\n",
      "[1.4603138e-06]\n",
      "[0.00953576]\n",
      "[0.]\n",
      "[3.5762787e-07]\n",
      "[5.9604645e-08]\n",
      "[0.]\n",
      "[0.3862053]\n",
      "[0.]\n",
      "[1.731515e-05]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.6886773]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.13103577]\n",
      "[0.]\n",
      "[2.682209e-07]\n",
      "[2.9802322e-08]\n",
      "[2.682209e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[2.3841858e-07]\n",
      "[0.]\n",
      "[0.00012225]\n",
      "[0.]\n",
      "[0.00024852]\n",
      "[1.1920929e-07]\n",
      "[4.172325e-07]\n",
      "[2.9802322e-07]\n",
      "[4.172325e-07]\n",
      "[0.]\n",
      "[0.00036609]\n",
      "[0.]\n",
      "[0.]\n",
      "[6.2584877e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[8.940697e-08]\n",
      "[0.]\n",
      "[1.7732382e-05]\n",
      "[0.20784023]\n",
      "[2.9802322e-08]\n",
      "[0.]\n",
      "[2.9802322e-07]\n",
      "[0.]\n",
      "[9.441376e-05]\n",
      "[0.00030035]\n",
      "[0.00966442]\n",
      "[0.]\n",
      "[3.5762787e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.0001581]\n",
      "[4.1037798e-05]\n",
      "[2.7120113e-06]\n",
      "[0.00018209]\n",
      "[0.]\n",
      "[0.00023389]\n",
      "[1.1891127e-05]\n",
      "[0.]\n",
      "[0.00032964]\n",
      "[6.2584877e-07]\n",
      "[0.00036779]\n",
      "[0.]\n",
      "[0.]\n",
      "[8.34465e-07]\n",
      "[6.854534e-07]\n",
      "[2.9802322e-07]\n",
      "[0.00026411]\n",
      "[7.4505806e-07]\n",
      "[0.]\n",
      "[0.00011176]\n",
      "[0.]\n",
      "[2.3841858e-07]\n",
      "[0.]\n",
      "[2.413988e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[8.34465e-07]\n",
      "[0.00022015]\n",
      "[9.262562e-05]\n",
      "[0.]\n",
      "[0.0002386]\n",
      "[0.00049552]\n",
      "[0.]\n",
      "[2.3841858e-07]\n",
      "[0.]\n",
      "[0.00196657]\n",
      "[0.]\n",
      "[0.00018293]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[7.531047e-05]\n",
      "[0.]\n",
      "[0.74015963]\n",
      "[4.7683716e-07]\n",
      "[1.6182661e-05]\n",
      "[0.]\n",
      "[8.940697e-08]\n",
      "[0.]\n",
      "[7.3730946e-05]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.99875176]\n",
      "[0.]\n",
      "[0.00012532]\n",
      "[0.]\n",
      "[0.03685793]\n",
      "[0.00014326]\n",
      "[0.00016236]\n",
      "[0.00272858]\n",
      "[0.00016502]\n",
      "[0.00075206]\n",
      "[5.364418e-07]\n",
      "[4.6133995e-05]\n",
      "[1.013279e-06]\n",
      "[6.854534e-07]\n",
      "[0.00089708]\n",
      "[2.9802322e-07]\n",
      "[0.]\n",
      "[0.95788527]\n",
      "[0.00010723]\n",
      "[0.01711756]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00705475]\n",
      "[0.00017825]\n",
      "[4.917383e-06]\n",
      "[0.0403623]\n",
      "[2.3841858e-07]\n",
      "[8.490682e-05]\n",
      "[0.]\n",
      "[1.2755394e-05]\n",
      "[0.]\n",
      "[0.]\n",
      "[6.2584877e-07]\n",
      "[0.]\n",
      "[2.9802322e-08]\n",
      "[0.]\n",
      "[4.1902065e-05]\n",
      "[1.4007092e-06]\n",
      "[1.6093254e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[2.7924776e-05]\n",
      "[0.]\n",
      "[0.00020593]\n",
      "[0.]\n",
      "[0.]\n",
      "[8.940697e-08]\n",
      "[1.4901161e-07]\n",
      "[0.00010118]\n",
      "[1.6987324e-06]\n",
      "[4.9471855e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[2.5629997e-06]\n",
      "[0.00026786]\n",
      "[1.5497208e-06]\n",
      "[5.9604645e-08]\n",
      "[1.4901161e-07]\n",
      "[1.1622906e-06]\n",
      "[0.]\n",
      "[5.751848e-06]\n",
      "[0.00010028]\n",
      "[7.6293945e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[7.015467e-05]\n",
      "[0.]\n",
      "[2.4437904e-06]\n",
      "[5.364418e-07]\n",
      "[0.9987751]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.8139123]\n",
      "[0.]\n",
      "[5.9604645e-07]\n",
      "[1.1920929e-06]\n",
      "[1.758337e-06]\n",
      "[7.44164e-05]\n",
      "[0.00035337]\n",
      "[0.]\n",
      "[5.9604645e-07]\n",
      "[0.]\n",
      "[2.9802322e-07]\n",
      "[0.20275265]\n",
      "[0.16549274]\n",
      "[7.0631504e-06]\n",
      "[1.4901161e-07]\n",
      "[0.7762959]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00132287]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[3.5762787e-07]\n",
      "[6.1661005e-05]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[2.2530556e-05]\n",
      "[3.5762787e-07]\n",
      "[6.198883e-06]\n",
      "[0.00023484]\n",
      "[2.9802322e-07]\n",
      "[0.]\n",
      "[8.940697e-08]\n",
      "[0.00033638]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.48010612]\n",
      "[0.]\n",
      "[0.]\n",
      "[8.6158514e-05]\n",
      "[0.00105456]\n",
      "[0.]\n",
      "[5.453825e-06]\n",
      "[1.4901161e-07]\n",
      "[6.0349703e-05]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[2.3841858e-07]\n",
      "[4.7326088e-05]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00112757]\n",
      "[0.]\n",
      "[0.]\n",
      "[6.854534e-07]\n",
      "[0.00018245]\n",
      "[0.00069579]\n",
      "[0.]\n",
      "[2.682209e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.9939556]\n",
      "[9.23872e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[1.2516975e-06]\n",
      "[1.4901161e-07]\n",
      "[0.]\n",
      "[7.748604e-07]\n",
      "[1.7881393e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[3.874302e-07]\n",
      "[1.1920929e-06]\n",
      "[0.]\n",
      "[1.7881393e-07]\n",
      "[0.]\n",
      "[0.00025204]\n",
      "[0.]\n",
      "[2.3961067e-05]\n",
      "[8.940697e-08]\n",
      "[0.00022066]\n",
      "[8.940697e-07]\n",
      "[6.341934e-05]\n",
      "[0.]\n",
      "[2.2172928e-05]\n",
      "[0.0069938]\n",
      "[1.847744e-06]\n",
      "[0.]\n",
      "[4.5001507e-06]\n",
      "[0.00109106]\n",
      "[0.002588]\n",
      "[8.6426735e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[6.377697e-06]\n",
      "[1.1026859e-06]\n",
      "[1.1920929e-06]\n",
      "[2.3841858e-07]\n",
      "[0.]\n",
      "[0.08853734]\n",
      "[3.2424927e-05]\n",
      "[0.01472989]\n",
      "[0.00026467]\n",
      "[0.]\n",
      "[0.8342678]\n",
      "[2.592802e-06]\n",
      "[0.]\n",
      "[3.2782555e-07]\n",
      "[0.]\n",
      "[0.07152978]\n",
      "[0.]\n",
      "[8.6426735e-07]\n",
      "[6.854534e-07]\n",
      "[0.]\n",
      "[0.13392982]\n",
      "[0.]\n",
      "[2.682209e-07]\n",
      "[0.]\n",
      "[5.3942204e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[2.092123e-05]\n",
      "[6.940961e-05]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00026]\n",
      "[0.00487873]\n",
      "[7.733703e-05]\n",
      "[2.3841858e-07]\n",
      "[2.9802322e-08]\n",
      "[0.00029761]\n",
      "[0.00027999]\n",
      "[0.]\n",
      "[0.0001055]\n",
      "[0.]\n",
      "[2.682209e-07]\n",
      "[0.0001899]\n",
      "[0.25748342]\n",
      "[1.0937452e-05]\n",
      "[0.]\n",
      "[0.29499596]\n",
      "[0.]\n",
      "[2.3841858e-07]\n",
      "[0.]\n",
      "[7.05421e-05]\n",
      "[0.02470398]\n",
      "[0.]\n",
      "[1.2725592e-05]\n",
      "[2.9802322e-08]\n",
      "[0.]\n",
      "[0.]\n",
      "[1.0728836e-06]\n",
      "[7.867813e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.03755283]\n",
      "[0.00020155]\n",
      "[1.6093254e-06]\n",
      "[0.]\n",
      "[0.00044]\n",
      "[0.00058937]\n",
      "[0.04277563]\n",
      "[0.]\n",
      "[0.9978926]\n",
      "[0.]\n",
      "[0.]\n",
      "[1.2814999e-06]\n",
      "[0.00017127]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00020653]\n",
      "[5.7816505e-06]\n",
      "[0.]\n",
      "[0.00020063]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.9878977]\n",
      "[6.7949295e-06]\n",
      "[5.9068203e-05]\n",
      "[0.]\n",
      "[1.7285347e-05]\n",
      "[0.00013223]\n",
      "[0.]\n",
      "[0.00019178]\n",
      "[3.0845404e-05]\n",
      "[1.7285347e-06]\n",
      "[0.]\n",
      "[0.00959575]\n",
      "[0.]\n",
      "[0.00017804]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00028279]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00032073]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.01124024]\n",
      "[1.1920929e-07]\n",
      "[2.9802322e-08]\n",
      "[0.00365788]\n",
      "[0.]\n",
      "[0.00087133]\n",
      "[0.00026369]\n",
      "[0.]\n",
      "[0.9454531]\n",
      "[5.364418e-07]\n",
      "[0.]\n",
      "[9.864569e-06]\n",
      "[0.]\n",
      "[0.00022924]\n",
      "[0.]\n",
      "[1.1622906e-06]\n",
      "[0.]\n",
      "[5.066395e-07]\n",
      "[0.00015011]\n",
      "[0.020715]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[1.1920929e-07]\n",
      "[2.5629997e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[3.963709e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[2.9802322e-08]\n",
      "[0.00041083]\n",
      "[0.0006521]\n",
      "[3.0100346e-06]\n",
      "[2.4437904e-06]\n",
      "[0.96758115]\n",
      "[0.99839324]\n",
      "[9.23872e-07]\n",
      "[0.00036597]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.4928071]\n",
      "[0.05550635]\n",
      "[1.1920929e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.02710465]\n",
      "[5.3048134e-06]\n",
      "[1.8298626e-05]\n",
      "[0.31290567]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00017405]\n",
      "[0.]\n",
      "[0.]\n",
      "[3.0368567e-05]\n",
      "[0.]\n",
      "[1.3113022e-06]\n",
      "[0.47539723]\n",
      "[0.00028726]\n",
      "[0.]\n",
      "[5.9604645e-08]\n",
      "[2.026558e-06]\n",
      "[0.]\n",
      "[3.5762787e-07]\n",
      "[2.9802322e-08]\n",
      "[3.2424927e-05]\n",
      "[0.00053817]\n",
      "[4.8577785e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.27670765]\n",
      "[0.00023714]\n",
      "[1.9073486e-06]\n",
      "[6.455183e-05]\n",
      "[0.]\n",
      "[5.9604645e-07]\n",
      "[0.]\n",
      "[7.3611736e-06]\n",
      "[2.2649765e-06]\n",
      "[0.00084373]\n",
      "[0.]\n",
      "[0.00023249]\n",
      "[0.]\n",
      "[0.9135123]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[1.1622906e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[6.3478947e-06]\n",
      "[0.11757898]\n",
      "[2.3841858e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[5.543232e-06]\n",
      "[3.33786e-06]\n",
      "[0.00057685]\n",
      "[3.8027763e-05]\n",
      "[0.]\n",
      "[2.9802322e-08]\n",
      "[0.]\n",
      "[0.]\n",
      "[2.0861626e-07]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00027505]\n",
      "[5.9604645e-08]\n",
      "[0.0144105]\n",
      "[0.8889185]\n",
      "[0.00026968]\n",
      "[0.8549955]\n",
      "[0.00039712]\n",
      "[0.23929936]\n",
      "[0.9973159]\n",
      "[0.]\n",
      "[1.5497208e-06]\n",
      "[0.94641817]\n",
      "[0.]\n",
      "[1.4305115e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00017485]\n",
      "[8.314848e-06]\n",
      "[0.]\n",
      "[1.0430813e-06]\n",
      "[0.]\n",
      "[2.5331974e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00027773]\n",
      "[0.00072244]\n",
      "[3.194809e-05]\n",
      "[0.00017548]\n",
      "[0.]\n",
      "[0.00018126]\n",
      "[0.]\n",
      "[2.682209e-07]\n",
      "[0.]\n",
      "[0.00224102]\n",
      "[0.00128916]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.]\n",
      "[1.1324883e-06]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.0002009]\n",
      "[0.00013077]\n",
      "[0.00022188]\n",
      "[0.]\n",
      "[0.0006738]\n",
      "[0.]\n",
      "[0.]\n",
      "[0.00703827]\n",
      "[0.00011709]\n",
      "[0.00034859]\n",
      "[0.54320115]\n",
      "Total 1554, predicted attacks 1437\n"
     ]
    }
   ],
   "source": [
    "conn = SQLConnector()\n",
    "data = conn.pull_kdd99(attack='nmap', num=1554)\n",
    "dataframe = pd.DataFrame.from_records(data=data,\n",
    "            columns=conn.pull_kdd99_columns(allQ=True))\n",
    "le = LabelEncoder()\n",
    "dataframe_encoded = dataframe.apply(le.fit_transform)\n",
    "dataset = dataframe_encoded.values\n",
    "pred = estimator.predict(dataset[:, 0:41])\n",
    "counter = 0\n",
    "for x in pred:\n",
    "    print(x)\n",
    "    if x[0] <= 0.01:\n",
    "        counter += 1\n",
    "print('Total %d, predicted attacks %d' % (len(pred), counter))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "from mysql import SQLConnector\n",
    "conn = SQLConnector()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "noise = np.random.normal(0, 1, (10, 41)) #927\n",
    "\n",
    "#create an array of generated attacks\n",
    "gen_attacks = generator.predict(noise).astype('int')\n",
    "estimator.predict(gen_attacks)\n",
    "#data = conn.pull_kdd99(attack='nmap', num=8)\n",
    "# for x in gen_attacks:\n",
    "#     conn.write_gens('927', x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8], x[9], x[10], \n",
    "#                     x[11], x[12], x[13], x[14], x[15], x[16], x[17], x[18], x[19], x[20], \n",
    "#                     x[21], x[22], x[23], x[24], x[25], x[26], x[27], x[28], x[29], x[30], \n",
    "#                     x[31], x[32], x[33], x[34], x[35], x[36], x[37], x[38], x[39], x[40], '18')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
